home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / RECORDS.SWG / 0001_BLOCKRW1.PAS.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  64 lines

  1. {
  2. Does anyone have any examples of how to Write Text to a File using
  3. blockWrite?
  4. }
  5. Program DemoBlockWrite;
  6.  
  7. Const
  8.   { Carriage-return + Line-feed Constant. }
  9.   co_CrLf = #13#10;
  10.  
  11. Var
  12.   st_Temp : String;
  13.   fi_Temp : File;
  14.   wo_BytesWritten : Word;
  15.  
  16. begin
  17.   { Assign 5 lines of Text to temp String. }
  18.   st_Temp := 'Line 1 of Text File' + co_CrLf + 'Line 2 of Text File'
  19.              + co_CrLf + co_CrLf + 'Line 4 of Text File' + co_CrLf +
  20.              ' My name is MUD ' + co_CrLf;
  21.  
  22.   assign(fi_Temp, 'TEST.TXT');
  23.   {$I-}
  24.   reWrite(fi_Temp, 1);
  25.   {$I+}
  26.   if (ioresult <> 0) then
  27.   begin
  28.     Writeln('Error creating TEST.TXT File');
  29.     Halt
  30.   end;
  31.   { Write 5 lines of Text to File. }
  32.   BlockWrite(fi_Temp, st_Temp[1], length(st_Temp), wo_BytesWritten);
  33.   { Check For errors writing Text to File. }
  34.   if (wo_BytesWritten <> length(st_Temp)) then
  35.   begin
  36.     Writeln('Error writing Text to File!');
  37.     Halt
  38.   end;
  39.   { Close File. }
  40.   Close(fi_Temp);
  41.   { Attempt to open Text File again. }
  42.   Assign(fi_Temp, 'TEST.TXT');
  43.   {$I-}
  44.   Reset(fi_Temp, 1);
  45.   {$I+}
  46.   if (IOResult <> 0) then
  47.   begin
  48.     Writeln('Error opening TEST.TXT File');
  49.     Halt
  50.   end;
  51.   st_Temp := 'Guy';
  52.   { Position File-Pointer just before the 'MUD' in Text. }
  53.   seek(fi_Temp, 77);
  54.   { Correct my name by overwriting old Text With new. }
  55.   blockWrite(fi_Temp, st_Temp[1], length(st_Temp), wo_BytesWritten);
  56.   { Check For errors writing Text to File. }
  57.   if (wo_BytesWritten <> length(st_Temp)) then
  58.   begin
  59.     Writeln('Error writing Text to File!');
  60.     Halt
  61.   end;
  62.   Close(fi_Temp)
  63. end.
  64.